import Vue from 'vue'
import co from 'co'

/**
 * 取得所有授权策略
 */
let getAllDataGen = function * () {
  let response = yield Vue.resetpost('/rs/logic/getLicenseData', {data:{}}, {resolveMsg: null, rejectMsg: null})
  return response.data
}

export function getAllData () {
  let gen = getAllDataGen()
  return co(gen)
}

/**
 * 取得资源的所有授权策略
 * @param res
 */
let getDataGen = function * (res) {
  let response = yield Vue.resetpost('/rs/license/getData', {parentid: res.id}, {resolveMsg: null, rejectMsg: null})
  return response.data
}

export function getData (res) {
  let gen = getDataGen(res)
  return co(gen)
}

/**
 * 取得所有被授权资源名称路径串，用","分割
 * @param res
 * @returns {*}
 */
let getDataNamesGen = function * (res) {
  let response = yield Vue.resetpost('/rs/license/getData', {parentid: res.id}, {resolveMsg: null, rejectMsg: null})
  let result = ''
  for (let license of response.data) {
    if (result !== '') {
      result += '|'
    }
    result += license.names
  }
  return result
}

export function getDataNames (res) {
  let gen = getDataNamesGen(res)
  return co(gen)
}
